//createRoute：创建路由实例
//createWebHistory：创建history模式路由(还有一种hash模式路由)
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import PayBack from '@/views/Money/PayBack.vue'
//订单页
import Payment from '@/views/Payment/index.vue'
//支付页
import Money from '@/views/Money/index.vue'
import Mvp from '@/views/Mvp/index.vue'
import PersonCenter from '@/views/Mvp/components/PersonCenter.vue'
import MyOrder from '@/views/Mvp/components/MyOrder.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  //routes:是配置path和component对应关系的位置
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          //默认首页/二级路由的时候，要置空path，什么都不写
          //二级路由不写/
          path: '',
          component: Home
        },
        {
          //拼接一个id占位符
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cartlist',
          component: CartList
        },
        {
          path: 'payment',
          component: Payment
        },
        {
          path: 'money',
          component: Money
        },
        {
          path: 'paycallback',
          component: PayBack
        },
        {
          path: 'mvp',
          component: Mvp,
          children: [
            {
              path: '',
              component: PersonCenter
            },
            {
              path: 'myorder',
              component: MyOrder
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      component: Login
    }

  ],
  //路由行为配置项
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
